package com.example.demo1102.demo3;

import java.util.concurrent.*;

public class CallableTest implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        int a=0;
        for (int j = 0; j < 101; j++) {
            a+=j;
        }
        return a;
    }
}
class Test{
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableTest callableTest = new CallableTest();
        FutureTask<Integer> integerFutureTask = new FutureTask<Integer>(callableTest);
        Thread thread = new Thread(integerFutureTask);
        thread.start();
        System.out.println(integerFutureTask.get());
    }
}

class Test01{
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Future<Integer> submit = executorService.submit(new CallableTest());
        try {
            System.out.println(submit.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executorService.shutdown();
    }

}
